package com.hzdl.cinema.Service.impl;

import com.hzdl.cinema.Service.RefundService;
import com.hzdl.cinema.dao.RefundDao;
import com.hzdl.cinema.dao.impl.RefundDaoImpl;
import com.hzdl.cinema.domain.PageBean;
import com.hzdl.cinema.domain.Ticket;


import java.util.List;

public class RefundServiceImpl implements RefundService {
    RefundDao refundDao=new RefundDaoImpl();
    @Override
    public PageBean<Ticket> seeTicke(Integer rows, Integer currentPage, String select_input) {
        PageBean<Ticket> pageBean=new PageBean<>();

        //    totalCount;//总条数
        int   totalCount= refundDao.totalRefund(select_input);
        pageBean.setTotalCount(totalCount);
        //    totalPage;//总页数
        int totalPage = totalCount % rows == 0 ? totalCount / rows : (totalCount / rows) + 1;
        pageBean.setTotalPage(totalPage);
        //    currentPage;//当前页
        pageBean.setCurrentPage(currentPage);
        //    rows;//每页的条数
        pageBean.setRows(rows);
        //list
        int index = (currentPage - 1) * rows;
        if (null==select_input){
        List<Ticket> list= refundDao.fiedRefund(index,rows);
        pageBean.setList(list);
        }else {
            List<Ticket> list= refundDao.fiedAllRefund(select_input);
            pageBean.setList(list);
        }

        return pageBean;
    }

    @Override
    public void updateTicket(String id) {
        refundDao.updateTicket(id);
    }
}
